<!--修改房间子组件-->
<template>
<div>
  <el-dialog title="新增界面" :visible.sync="showFlag" @close="closeDialog" width="40%">
    <el-form ref="addRoomForm" :model="addRoomForm" :rules="addRoomRules" label-width="90px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="房间编号:" prop="rid">
            <el-input v-model="addRoomForm.rid" placeholder="请输入房间编号" style="width: 100%"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公寓编号:" prop="apt_id">
            <el-input v-model="addRoomForm.apt_id" placeholder="请输入房间编号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="房间类型:" prop="type">
            <el-select v-model="addRoomForm.type" placeholder="请选择房间类型" style="width: 100%">
              <el-option label="二人间" value="2"></el-option>
              <el-option label="四人间" value="4"></el-option>
              <el-option label="八人间" value="8"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="房间价格:" prop="price">
            <el-input v-model="addRoomForm.price" placeholder="请输入房间价格"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item class="dialog-footer" align="center">
        <el-button type="success" @click="onSave('addRoomForm')">保 存</el-button>
        <el-button @click="onCancel('addRoomForm')">取 消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</div>
</template>

<script>
export default {
name: "addRoom",
  data(){
  return{
    addRoomForm:{
      id:'',
      rid:'',
      apt_id:'',
      type:'',
      price:'',
    },
    addRoomRules:{
      id:[{required:true,message: '请输入编号',trigger: 'blur'}],
      rid:[{required:true,message: '请输入房间编号',trigger: 'blur'}],
      apt_id:[{required:true,message: '请输入公寓编号',trigger: 'blur'}]
    },
    showFlag:false,
  }
  },
  methods:{
    //初始化
    init(){
      this.showFlag=true
    },
  //关闭对话框的回调函数
    closeDialog(){
      this.$refs.addRoomForm.resetFields()
    },
    //保存
    onSave(){
      this.$refs.addRoomForm.validate(async valid=>{
        if(valid){
          let params={
            id:this.addRoomForm.id,
            rId:this.addRoomForm.rid,
            apt_id:this.addRoomForm.apt_id,
            price:this.addRoomForm.price,
            type:this.addRoomForm.type
          }
          const {data:res} =await this.$http.post('/room/insertRoom',params)
          if(res.code!=200) return this.$message.error('添加房间信息失败~')
          this.$message.success('添加房间信息成功~')
        }
      })
      this.$emit('addClickBack')
      this.showFlag=false
    },
    //取消
    onCancel(){
      this.showFlag=false
      this.$refs.addRoomForm.resetFields()
    }
  }
}
</script>

<style scoped>

</style>